﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Operator_BankAccounts : System.Web.UI.Page
{
    BankDataDataContext db = new BankDataDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void CreateBankAccountButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Operator/OpenBankAccount.aspx");
    }

    protected void BankAccountsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            LinkButton linkButton = (LinkButton)e.Row.FindControl("RefillBankAccountLinkButton");
            string bankAccountId = e.Row.Cells[0].Text;
            linkButton.CommandArgument = bankAccountId;
        }
    }

    protected void RefillBankAccountClicked(object sender, EventArgs e)
    {
        LinkButton linkButton = (LinkButton)sender;
        Session.Add("bankAccountId", linkButton.CommandArgument);
        Response.Redirect("~/Operator/RefillBankAccount.aspx");
    }

    protected void BankAccountsGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        string bankAccountId = BankAccountsGridView.SelectedRow.Cells[0].Text;
        var bankAccounts = from bankAccount in db.BankAccounts where bankAccount.BankAccountId == Convert.ToInt32(bankAccountId) select bankAccount;
        var bankAccountsCompany = from bankAccountCompany in db.BankAccountCompanies where bankAccountCompany.BankAccountId == Convert.ToInt32(bankAccountId) select bankAccountCompany;
        db.BankAccountCompanies.DeleteOnSubmit(bankAccountsCompany.First());
        db.BankAccounts.DeleteOnSubmit(bankAccounts.First());
        db.SubmitChanges();
        Response.Redirect("~/Operator/BankAccounts.aspx");
    }
}